package com.lbssoft.gpsbd.dao;

import java.util.List;

import org.apache.ibatis.annotations.*;

import com.lbssoft.gpsbd.dao.sql.GeofenceSql;
import com.lbssoft.gpsbd.model.Geofence;
import com.lbssoft.gpsbd.model.GeofencePermission;

@Mapper
public interface GeofenceMapper {
	/**
	 * 添加围栏
	 * @param 
	 */
	@Insert("INSERT INTO lbs_geofences(uuid,name,type,area,description) VALUE(#{uuid},#{name},#{type},#{area},#{description})")
	@Options(useGeneratedKeys=true, keyProperty="id")
	void add(Geofence geofence);
	
	@Insert("INSERT INTO lbs_user_geofence(userId,geofenceId) VALUE(#{userId},#{geofenceId})")
	void addUserGeofence(GeofencePermission geofencePermission);
	
	@Select("SELECT t.* FROM lbs_geofences t INNER JOIN lbs_user_geofence a ON a.geofenceid = t.id WHERE a.userId = #{uid}")
	List<Geofence> getGeofences(@Param("uid") long uid);
	
	@UpdateProvider(type = GeofenceSql.class, method = "update")
	void update(Geofence geofence);

	/**
	 * 删除围栏
	 * @param id
     */
	@Delete("DELETE FROM lbs_geofences WHERE id = #{id}")
	void delete(@Param("id") long id);

	@Select("SELECT * FROM lbs_geofences where id = #{id}")
	Geofence getInfo(@Param("id") long id);

	@Select("SELECT * FROM lbs_geofences")
	List<Geofence> getAllGeofences();
	
	
}
